<?php defined('IN_NWIDC') or exit('Access Invalid!');?>

<?php


?>

<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3>场馆管理</h3>
      <ul class="tab-base">
        <li><a href="JavaScript:void(0);" class="current"><span>场馆管理</span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  
  <style>
  #addform p{
    line-height: 35px;
  }
    #addform p span{
      display: inline-block;
      *display: inline;
      width: 80px;
      margin-right: 15px;
    }
    #addform{
      padding: 15px;
      border : 1px solid #ddd;
    }
  </style>
  <div id='addform'>
      <p>
        <span>名称：</span><input type="text" name='name'>
      </p>    
      <p style='padding-top: 15px;'>
        <a href="javascript:;" class='btn'>新增</a>
      </p>
  </div>
  <script>
      $('#addform .btn').click(function(){
          var name = $('#addform [name=name]').val();
          if(name == ''){
              alert('名称不能为空！');
              return;
          }

          $.post('?act=web_config&op=addnew',{name : name},function(msg){
              location.reload();
          });

          // $('#addform').find('input').val('');
      });

      $(function(){
        $('#place_table input').blur(function(){
          var val = this.value;
          var id = $(this).closest('tr').find('input[type=checkbox]').val();
          var data = {id : id};
          data[this.name] = this.value
          $.post('?act=web_config&op=update_place',data);
        });
      })
  </script>


  <table class="table tb-type2" id="prompt">
    <tbody>
      <tr class="space odd">
        <th colspan="12"><div class="title">
            <h5><?php echo $lang['nc_prompts'];?></h5>
            <span class="arrow"></span></div></th>
      </tr>
      <tr>
        <td><ul>
            <li><?php echo $lang['adv_help2'];?></li>
          </ul></td>
      </tr>
    </tbody>
  </table>
  <form method="post" id="store_form" act='index.php?act=web_config&op=delete_place'>
    <input type="hidden" name="form_submit" value="ok" />
    <?php
      $places = Model('place')->select();
    ?>
    <table class="table tb-type2" id='place_table'>
      <thead>
        <tr class="thead">
          <th><input type="checkbox" class="checkall"/></th>
          <th>场馆名</th>
          <th>广告位</th>
          <th>商品广告词</th>
          <th class="align-center">操作</th>
          
        </tr>
      </thead>
      <tbody>
        <?php
          if(!empty($places)){
          foreach($places as $p){
        ?>
        <tr class="hover">
          <td class="w24">
            <input type="checkbox" class='checkitem' name='del_id[]'  value='<?php echo $p['id']?>' >
          </td>
          <td>
            <input type="text" value='<?php echo $p[name]?>' name='name'>
          </td>

          <td >
            <input type="text" value='<?php echo $p[adv]?>' class='w200' name='adv'>
            <a href="javascript:;" class='insert'>插入</a>

          </td>

          <td>
            <input type="text" value='<?php echo $p['ad_word']?>' class='w200' name='ad_word'>
            <a href="javascript:;" class='insert'>插入</a>
          </td>

          <td class='align-center'>
            <a target='_blank' href="/index.php?act=show_place&id=<?php echo $p[id]?>">查看</a>
          </td>
        </tr>
        <?php    
          }
          }
          else{
        ?>
        <tr class="no_data">
          <td colspan="15"><?php echo $lang['nc_no_record'];?></td>
        </tr>
        <?php    
          }
        ?>
       
      </tbody>
      <tfoot>
        <tr class="tfoot">
          <td><input type="checkbox" class="checkall" id="checkall"/></td>
          <td id="batchAction" colspan="15"><span class="all_checkbox">
            <label for="checkall"><?php echo $lang['nc_select_all'];?></label>
            </span>&nbsp;&nbsp;<a href="JavaScript:void(0);" class="btn" onclick="if(confirm('确定删除吗？')){removeOP()}"><span><?php echo $lang['nc_del'];?></span></a>
            <div class="pagination"> <?php echo $output['page'];?> </div></td>
        </tr>
      </tfoot>
    </table>
  </form>
</div>

<div id='ads' style='display: none;'>
  <table class='table tb-type2' >
    <thead>
      <th>名称</th>
      <th>宽</th>
      <th>高</th>
      <th>操作</th>
    </thead>
    <?php
    $ads = Model('adv_position')->where(array('is_use' => 1))->order('ap_id desc')->select();
    foreach($ads as $v){
    ?>
    <tr>
      <td><?php echo $v['ap_name']?></td>
      <td><?php echo $v['ap_width']?></td>
      <td><?php echo $v['ap_height']?></td>
      <td><a href="javascript:;" data-id='<?php echo $v['ap_id']?>'>插入</a></td>
    </tr>
    <?php  
    }
    ?>
  </table>
</div>
<script>
  
  function removeOP(){
    var form = $('#store_form');
    var data = []
    form.find('input:checked').each(function(){
      data.push(this.value);

    });
    $.post('?act=web_config&op=delete_place',{data : data},function(){
      location.reload();
    })
  }
</script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery.edit.js" charset="utf-8"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/dialog/dialog.js" id="dialog_js" charset="utf-8"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/layer/layer.js"></script>
<script>
//弹出复制代码框
function copyToClipBoard(id)
{
   ajax_form('copy_adv', '<?php echo $lang['ap_get_js'];?>', 'index.php?act=adv&op=ap_copy&id='+id);
}

<?php
?>
function insert_ad(){
    layer.open({
      type: 1,
      shade: false,
      title: false, //不显示标题
      content: $('#ads'), //捕获的元素
      area : ['800px'],
      cancel: function(index){
          layer.close(index);
          // this.content.show();
          // layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', {time: 5000, icon:6});
      }
  });
}
var target_input = null;
$('.insert').click(function(){
  target_input = $(this).prev();
  insert_ad();
});

$('#ads a').click(function(){
  var id = $(this).attr('data-id');
  layer.closeAll();
  target_input.val('<script type="text/javascript" src="/shop/index.php?act=adv&op=advshow&ap_id=' + id + '"><\/script>')
});
</script>
